<?php

namespace app\admin\model\wanlshop;

use think\Model;
use traits\model\SoftDelete;

class OrderItem extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'wanlshop_order_item';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'type_text',
        'consumption_text',
        'specs_text',
        'validity_text',
        'stock_text',
        'activity_text',
        'distribution_text',
        'flag_text',
        'activity_type_text',
        'status_text'
    ];
    

    
    public function getTypeList()
    {
        return ['1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3'), '4' => __('Type 4'), '5' => __('Type 5')];
    }

    public function getConsumptionList()
    {
        return ['1' => __('Consumption 1'), '2' => __('Consumption 2'), '3' => __('Consumption 3'), '4' => __('Consumption 4')];
    }

    public function getSpecsList()
    {
        return ['1' => __('Specs 1'), '2' => __('Specs 2')];
    }

    public function getValidityList()
    {
        return ['0' => __('Validity 0'), '1' => __('Validity 1'), '3' => __('Validity 3')];
    }

    public function getStockList()
    {
        return ['0' => __('Stock 0'), '2' => __('Stock 2'), '3' => __('Stock 3')];
    }

    public function getActivityList()
    {
        return ['0' => __('Activity 0'), '1' => __('Activity 1')];
    }

    public function getDistributionList()
    {
        return ['0' => __('Distribution 0'), '1' => __('Distribution 1')];
    }

    public function getFlagList()
    {
        return ['type' => __('Flag type'), 'name' => __('Flag name'), 'rec' => __('Flag rec')];
    }

    public function getActivityTypeList()
    {
        return ['goods' => __('Activity_type goods'), 'groups' => __('Activity_type groups'), 'seckill' => __('Activity_type seckill'), 'bargain' => __('Activity_type bargain')];
    }

    public function getStatusList()
    {
        return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getConsumptionTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['consumption']) ? $data['consumption'] : '');
        $list = $this->getConsumptionList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getSpecsTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['specs']) ? $data['specs'] : '');
        $list = $this->getSpecsList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getValidityTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['validity']) ? $data['validity'] : '');
        $list = $this->getValidityList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStockTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['stock']) ? $data['stock'] : '');
        $list = $this->getStockList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getActivityTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['activity']) ? $data['activity'] : '');
        $list = $this->getActivityList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getDistributionTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['distribution']) ? $data['distribution'] : '');
        $list = $this->getDistributionList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getFlagTextAttr($value, $data)
    {
        $value = $value ?: ($data['flag'] ?? '');
        $valueArr = explode(',', $value);
        $list = $this->getFlagList();
        return implode(',', array_intersect_key($list, array_flip($valueArr)));
    }


    public function getActivityTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['activity_type']) ? $data['activity_type'] : '');
        $list = $this->getActivityTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    protected function setFlagAttr($value)
    {
        return is_array($value) ? implode(',', $value) : $value;
    }


}
